Skip to content

Fix editable ComboBox text contrast in Desert high-contrast theme#790

Open
amarinov-msft wants to merge 2 commits into
microsoft:mainfrom
amarinov-msft:amarinov/combo-text-desert
Open

Fix editable ComboBox text contrast in Desert high-contrast theme#790
amarinov-msft wants to merge 2 commits into
microsoft:mainfrom
amarinov-msft:amarinov/combo-text-desert

Conversation

@amarinov-msft

@amarinov-msft amarinov-msft commented Jun 29, 2026

Copy link
Copy Markdown

Summary
Fixes an accessibility issue in the WPF Gallery ComboBox page. The editable ComboBox's focused text rendered at only ~4.292:1 contrast under the Desert contrast theme, below the 4.5:1 minimum required by MAS 4.3.1 and is flagged by Accessibility Insights. The Fluent theme draws the editable text with ComboBoxForeground/ComboBoxForegroundFocused, whose Desert color pairing is borderline.

Change
Sample Applications/WPFGallery/Views/BasicInput/ComboBoxPage.xaml.cs
Override ComboBoxForeground and ComboBoxForegroundFocused to full-contrast WindowText when SystemParameters.HighContrast is set, scoped to this page only. On focus, place the caret at the end instead of selecting all text, so the value isn't highlighted.

Sample Applications/WPFGallery/Views/BasicInput/ComboBoxPage.xaml
Hook GotKeyboardFocus on the editable ComboBox to drive the deselect behavior.

Result
Under high contrast the editable ComboBox text renders at the theme's full WindowText color, above the 4.5:1 minimum, so the Accessibility Insights Text Contrast check passes. Normal Light/Dark appearance is unchanged.

Testing

  • Built WPFGallery.csproj (0 errors).
  • Verified the editable ComboBox under the Desert contrast theme (now > 4.5:1, no select-all highlight).
Microsoft Reviewers: Open in CodeFlow

Use full-contrast WindowText for the editable ComboBox in high contrast (was ~4.292:1) and place the caret at end instead of selecting all on focus, so the value isn't highlighted.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dipeshmsft dipeshmsft added the Accessibility An issue related to accessibility enhancements or blockers. label Jul 1, 2026
@dipeshmsft

Copy link
Copy Markdown
Member

@amarinov-msft, I think this is more of a WPF's ComboBox style issue. We should be updating the color of TextControlSelectionHighlightColor brush in Fluent.HC.xaml.

Similarly, we should try overriding the resource value in the app resources and use that instead.

…color

Fluent's high-contrast theme sets TextControlSelectionHighlightColor to WindowColor, so editable ComboBox text is washed out (unreadable) when auto-selected on focus. Override that resource with the system Highlight color under high contrast, scoped to ComboBoxPage. Keeps standard select-on-focus behavior while making the selected text legible; Light/Dark selection is unaffected.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@amarinov-msft

Copy link
Copy Markdown
Author

I updated the approach. Here are the numbers from the Accessibility tool:
Screenshot

InitializeComponent();

// Fluent's HC selection color is WindowColor, washing out editable text selected on focus; use the Highlight color instead.
if (SystemParameters.HighContrast)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need to do something similar to what we did in MainWindow.xaml.cs.

Although, this code would work when the app / page is initialized. However, if we are on the page and the theme changes to something else, it may end up in wrong visuals.

Apart from that this is exactly what I was talking about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Accessibility An issue related to accessibility enhancements or blockers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants